package site.jlopen.controller.modules;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import site.jlopen.components.entity.GrapGroup;
import site.jlopen.components.entity.GraphNodeParam;
import site.jlopen.components.utils.GrapDataUtil;
import site.jlopen.entity.BaseResponse;
import site.jlopen.entity.grap.RenderAttrValueInfo;
import site.jlopen.service.intf.project.GraphService;
import site.jlopen.utils.id.IdUtils;

@RestController
@RequestMapping("/graph")
public class GraphController {

	@Autowired
    private GraphService graphService;

	@GetMapping("/createId")
	public Long createId() {
		return IdUtils.SnowFlakeId();
	}
	
	@GetMapping("/graphGroup")
	public List<GrapGroup> grapGroup() {
		//List<GrapGroup> list = GrapDataUtil.getGrapGroup();
		List<GrapGroup> list =  graphService.getGrapGroup();
		return list;
	}

	@PostMapping("/saveGraph")
	public BaseResponse<String> saveGraph(Long flowId, String grapJson) {
		return graphService.saveGraph(flowId, grapJson);
	}

	@GetMapping("/loadGraph")
	public BaseResponse<String> loadGraph(Long flowId) {
		return graphService.loadGraph(flowId);
	}

	@PostMapping("/loadNodeAttr")
	public BaseResponse<GraphNodeParam> loadNodeAttr(Long projectId, Long flowId, String graphId, String nodeCode) {
		return graphService.loadNodeAttr(projectId, flowId, graphId, nodeCode);
	}

	@PostMapping("/saveNodeAttr")
	public BaseResponse<String> saveNodeAttr(@RequestBody GraphNodeParam param) {
		return graphService.saveNodeAttr(param);
	}

	// 渲染节点属性可使用数值
	@PostMapping("/renderAttrValue")
	public BaseResponse<RenderAttrValueInfo> renderAttrValue(Long projectId, Long flowId, 
			String graphId, String nodeCode, String attrCode) {
		return graphService.renderAttrValue(projectId, flowId, graphId, nodeCode, attrCode);
	}
}
